package com.pomr.model.form;

import java.io.Serializable;
import java.text.SimpleDateFormat;

import com.pomr.model.health.PersonRecord;
import com.pomr.model.menu.HealthCondition;
import com.pomr.model.menu.Industry;
import com.pomr.model.menu.Marriage;
import com.pomr.model.menu.Sex;
import com.pomr.model.sys.Agency;
import com.pomr.model.sys.City;
import com.pomr.model.sys.Coutry;
import com.pomr.model.sys.Province;
import com.pomr.model.sys.User;
import com.pomr.util.common.IdcardUtils;

public class PersonRecordUp implements Serializable{
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getIdcard() {
		return idcard;
	}
	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}
	public String getProvince() {
		return province;
	}
	public void setProvince(String province) {
		this.province = province;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getCoutry() {
		return coutry;
	}
	public void setCoutry(String coutry) {
		this.coutry = coutry;
	}
	public String getAddr() {
		return addr;
	}
	public void setAddr(String addr) {
		this.addr = addr;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public String getIndustry() {
		return industry;
	}
	public void setIndustry(String industry) {
		this.industry = industry;
	}
	public String getMarriage() {
		return marriage;
	}
	public void setMarriage(String marriage) {
		this.marriage = marriage;
	}
	public String getHealthCondition() {
		return healthCondition;
	}
	public void setHealthCondition(String healthCondition) {
		this.healthCondition = healthCondition;
	}
	public String getAgency() {
		return agency;
	}
	public void setAgency(String agency) {
		this.agency = agency;
	}
	
	private String name;//姓名
	private String idcard;//身份证号
	private String province;//省
	private String city;//市
	private String coutry;//县
	private String addr;//详细地址
	private String tel;//电话
	private String industry;//职业
	private String marriage;//婚姻状况
	private String healthCondition;//健康状况
	private String agency;//所属机构编号
	
	/**
	 * 获取健康档案bean
	 * @return
	 */
	public PersonRecord getRecord() throws Exception{
		PersonRecord pr = new PersonRecord();
		if(this.idcard == null || this.idcard.equals("")){
			throw new Exception("身份证号为必传项");
		}
		if(!IdcardUtils.validateCard(this.idcard)){
			throw new Exception("身份证号"+this.idcard+"不合法");
		}
		pr.setName(this.name);
		pr.setIdcard(this.idcard);
		
		//出生日期
		pr.setBirth(new SimpleDateFormat("yyyyMMdd").parse(IdcardUtils.getBirthByIdCard(this.idcard)));
		//性别
		Sex s = new Sex();
		s.setId(IdcardUtils.getGenderByIdCard(this.idcard));
		pr.setSex(s);
		
		//地址
		Province p = new Province();
		p.setId(this.province);
		pr.setProvince(p);
		City c = new City();
		c.setId(this.city);
		pr.setCity(c);
		Coutry ct = new Coutry();
		ct.setId(this.coutry);
		pr.setCoutry(ct);
		pr.setAddr(this.addr);
		
		pr.setTel(this.tel);
		Agency a = new Agency();
		a.setIdentifier(this.agency);
		pr.setAgency(a);
		User u = new User();
		u.setId(1);
		pr.setUser(u);//默认上传用户为超级用户
		
		//职业
		Industry i = new Industry();
		if(this.industry==null || this.industry.equals("")){
			i.setId(1);
		}else{
			i.setId(Integer.valueOf(this.industry));
		}
		pr.setIndustry(i);
		//健康状况
		HealthCondition h = new HealthCondition();
		if(this.healthCondition==null || this.healthCondition.equals("")){
			h.setId(1);
		}else{
			h.setId(Integer.valueOf(this.healthCondition));
		}
		pr.setHealthCondition(h);
		//婚姻状况
		Marriage m = new Marriage();
		if(this.marriage==null || this.marriage.equals("")){
			m.setId(1);
		}else{
			m.setId(Integer.valueOf(this.marriage));
		}
		pr.setMarriage(m);
		
		return pr;
	}
	
}
